package com.glut.gultguy.controller;


import com.glut.gultguy.entity.Address;
import com.glut.gultguy.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService service;

    @GetMapping("/getAddr/{id}")
    @ResponseBody
    public List<Address> getUserAddress(@PathVariable("id") String publisherId){
        return service.getAddr(publisherId);
    }
    @GetMapping("/getAddrByOpenid/{id}")
    public List<Address> getAddrByOpenid(@PathVariable("id") String openid){
        return service.getAddrByOpenid(openid);
    }

    @PostMapping("/addAddr")
    @ResponseBody
    public Map<String,Integer> addAddress(@RequestBody Address address){
        return service.addAddr(address);
    }

    @PostMapping("/updateAddress")
    public boolean updateAddr(@RequestBody Address address){
        return service.updateById(address);
    }
}

